package com.ggh.jinjilive.dialog.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemGiftBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.live.GiftSouvenirMobile;

import java.util.List;


public class GiftLiveAdapter1 extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<GiftSouvenirMobile> giftMobile1s;
    public void GiftData3(List<GiftSouvenirMobile> giftMobile1s){

        this.giftMobile1s = giftMobile1s;
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemGiftBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_gift, parent, false);
        return new ViewHolder(binding);
    }



    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder, int position) {
        ViewHolder holder = (ViewHolder)recyclerViewholder;
        GiftSouvenirMobile giftMobile1 = giftMobile1s.get(position);
        if(null != giftMobile1){
            if(giftMobile1.isSelected()){
                holder.binding.llBackdrop.setBackgroundResource(R.drawable.bg_5_0bd2f1);
            }else {
                holder.binding.llBackdrop.setBackgroundResource(0);
            }

            Glide.with(holder.binding.ivGiftImg.getContext()).load(giftMobile1.getStatic_img_url()).into(holder.binding.ivGiftImg);
            holder.binding.ivGiftName.setText(giftMobile1.getName());
            holder.binding.ivGiftPrice.setText(giftMobile1.getPrice() + "钻石");
            holder.binding.llBackdrop.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,giftMobile1);
                    }
                }
            });
        }

    }



    @Override
    public int getItemCount() {
        return null == giftMobile1s ? 0 : giftMobile1s.size();
    }




    public class ViewHolder extends RecyclerView.ViewHolder {
        ItemGiftBinding binding;

        public ViewHolder(@NonNull ItemGiftBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
            ViewGroup.LayoutParams params =  binding.ivGiftImg.getLayoutParams();
            params.height = ScreenUtils.getScreenWidth() / 4 - SizeUtils.dp2px(10);
            binding.ivGiftImg.setLayoutParams(params);
        }
    }




    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener){
        this.addItemOnClickListener = addItemOnClickListener;
    }
}
